﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Input;

using SBPweb.RIA.Client.Controls.Base;

using SBPweb.PlAzureNet.Client.Library;
using SBPweb.PlAzureNet.Client.Library.Services.Data;

namespace SBPweb.PlAzureNet.Client.Library.Controls
{

    public partial class MainControl : UserControlBase
    {

        public MainControl()
        {
            //Connector.Instance.Dispatcher = this.Dispatcher;

            InitializeComponent();

            Loaded += new RoutedEventHandler(MainControl_Loaded);
            Unloaded += new RoutedEventHandler(MainControl_Unloaded);
            //Connector.Instance.LoggedIn += new EventHandler(Connector_LoggedIn);
        }

        public static readonly DependencyProperty SocialContentProperty = DependencyProperty.Register("SocialContent", typeof(object), typeof(ToolBarButton), null);

        public object SocialContent
        {
            get
            {
                return GetValue<object>(SocialContentProperty);
            }
            set
            {
                SetValue<object>(SocialContentProperty, value, "SocialContent");
                cpSocialContent.Content = value;
            }
        }

        private void MainControl_Loaded(object sender, RoutedEventArgs e)
        {
            Type t = typeof(MainControl);
            imgLogo.Source = t.GetEmbeddedBitmapImage("Resources.PlAzureNet_Logo_160x180.png");

            //Connector.Instance.Login();
        }

        private void MainControl_Unloaded(object sender, RoutedEventArgs e)
        {
            //Connector.Instance.Logout();
        }

        private void Connector_LoggedIn(object sender, EventArgs e)
        {
            //Type t = typeof(User);
            //User user = Connector.Instance.User as User;
            //imgFace.Source = new BitmapImage(user.AvatarUri);
            //if (user.Gender != Genders.Unknown)
            //{
            //    imgGender.Source = t.GetEmbeddedBitmapImage(string.Format("Resources.{0}_100x100.png", user.Gender.ToString()));
            //}
            //tbkName.Text = user.FullName;
        }

        private void ToolBarButton_MouseClick(object sender, MouseButtonEventArgs e)
        {
            ToolBarButton tbb = (sender as FrameworkElement).Parent as ToolBarButton;
            grdBack.Fill = new SolidColorBrush(tbb.ButtonFace);

            cContent.Content = Activator.CreateInstance(tbb.ContentType);
        }

        private void imgLogo_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            grdBack.Fill = new SolidColorBrush(Color.FromArgb(0xCC, 0x7C, 0xC5, 0xFA));
        }

    }

}